package com.itheima.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Demo1Servlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//响应的乱码
		response.setContentType("text/html;charset=utf-8");
		String username = request.getParameter("username");
		//请求的乱码
		String string = new String(username.getBytes("iso-8859-1"),"utf-8");
		//生成响应
		response.getWriter().print(string);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		//响应的乱码
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		String username = request.getParameter("username");
		//请求的乱码
		//String string = new String(username.getBytes("iso-8859-1"),"utf-8");
		//生成响应
		response.getWriter().print(username);
	}
}